package com.admin.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Service;

import com.admin.model.ChainGw;
import com.admin.model.ChainGwCx;

@Service("Chain219Dao")
public class Chain219Dao extends JdbcDaoSupport{

	@Resource
	public void setJb(JdbcTemplate jdbctemplate219) {
		super.setJdbcTemplate(jdbctemplate219);
	}
	public int getCountGwcx(ChainGwCx cxtj) {
		String sql="select count(*) from t_4B73D980100615A2A48FC7797B201171EAA60A38 where  status = '0'";
		if(cxtj.getBt()!=null&&!cxtj.getBt().equals("")){
			sql+=" and bt like '%"+unicode.string2Unicode(cxtj.getBt())+"%'";
		}
		if(cxtj.getWh()!=null&&!cxtj.getWh().equals("")){
			sql+=" and wh like '%"+unicode.string2Unicode(cxtj.getWh())+"%'";
		}
		if(cxtj.getFwrqq()!=null&&!cxtj.getFwrqq().equals("")){
			sql+=" and fwrq > '"+cxtj.getFwrqq()+"'";
		}
		if(cxtj.getFwrqz()!=null&&!cxtj.getFwrqz().equals("")){
			sql+=" and fwrq < '"+cxtj.getFwrqz()+"'";
		}
		return this.getJdbcTemplate().queryForInt(sql);
	}
	public List<ChainGw> findGwByPage(String page, ChainGwCx cxtj) {
		List<ChainGw> list=new ArrayList<ChainGw>();
		String sql="select * from t_4B73D980100615A2A48FC7797B201171EAA60A38 where status = '0'";
		if(cxtj.getBt()!=null&&!cxtj.getBt().equals("")){
			sql+=" and bt like '%"+unicode.string2Unicode(cxtj.getBt())+"%'";
		}
		if(cxtj.getWh()!=null&&!cxtj.getWh().equals("")){
			sql+=" and wh like '%"+unicode.string2Unicode(cxtj.getWh())+"%'";
		}
		if(cxtj.getFwrqq()!=null&&!cxtj.getFwrqq().equals("")){
			sql+=" and fwrq > '"+cxtj.getFwrqq()+"'";
		}
		if(cxtj.getFwrqz()!=null&&!cxtj.getFwrqz().equals("")){
			sql+=" and fwrq < '"+cxtj.getFwrqz()+"'";
		}
		sql+= " order by tjsj desc limit "+(Integer.valueOf(page)-1)*10+",10";
		//List<Map<String, Object>> list1=this.getJdbcTemplate().queryForList("select * from t_4B73D980100615A2A48FC7797B201171EAA60A38 order by tjsj desc limit "+(Integer.valueOf(page)-1)*10+",10");
		List<Map<String, Object>> list1=this.getJdbcTemplate().queryForList(sql);
		for(Map<String, Object> m:list1){
			ChainGw c=new ChainGw();
			c.setBt(unicode.unicode2String((String)m.get("bt")));
			c.setWh(unicode.unicode2String((String)m.get("wh")));
			c.setGkzrbm(unicode.unicode2String((String)m.get("gkzrbm")));
			c.setSsjg(unicode.unicode2String((String)m.get("ssjg")));
			c.setFwrq((String)m.get("fwrq"));
			c.setZwcclj("http://192.168.0.216:8080/uploadFiles/"+((String)m.get("zwcclj")).replace("C:\\apache-tomcat-7.0.69\\webapps\\uploadFiles\\", ""));
			c.setTjr((String)m.get("tjr"));
			list.add(c);
		}
		return list;
	}

}
